{
语法百题 解题报告：
 http://git.oschina.net/et0662/sznoi-grammar/ 
}
var
	a:array[false..true,1..12] of integer=((31,28,31,30,31,30,31,31,30,31,30,32),(31,29,31,30,31,30,31,31,30,31,30,32));
	w,s,y,m,i:integer;
	d:integer=0;
	leap:boolean;
begin
	readln(y,m);
	s:=y-1+((y-1)div 4)-((y-1)div 100)+((y-1)div 400)+1;
	w:=s mod 7;
	leap:= ((y mod 400)=0) or ( ((y mod 4)=0) and ((y mod 100)<>0));
	for i:=1 to m-1 do
		d:=d+a[leap][i];
	writeln('Sun Mon Tue Wed Thu Fri Sat ');
	w:=(w+d) mod 7;
	s:=0;
	for i:=0 to w-1 do
	begin
		write('    ');
		inc(s);
	end;
	for i:= 1 to a[leap][m-1] do
	begin
		inc(s);
		write(i:4);
		if(s=7)then
		begin
			writeln;
			s:=0;
		end;
	end;
end.
